package com.jic.member.controller.manage;

import com.jic.common.base.vo.PageResult;
import com.jic.common.base.vo.RestResult;
import com.jic.member.entity.MememberGrowthAction;
import com.jic.member.request.MemberGrowthActionApiRequest;
import com.jic.member.request.MemberGrowthRuleRequest;
import com.jic.member.response.MemberGrowthActionApiResponse;
import com.jic.member.response.MemberGrowthRuleResponse;
import com.jic.member.service.MememberGrowthActionService;
import com.jic.member.service.MememberGrowthRuleService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("growthRule")
@Slf4j
public class MemberGrowthRuleController {
    @Autowired
    private MememberGrowthRuleService mememberGrowthRuleService;
    @Autowired
    private MememberGrowthActionService mememberGrowthActionService;

    @ApiOperation("页面查询")
    @RequestMapping("getMemberGrowthRule")
    public RestResult<PageResult<MemberGrowthRuleResponse>> getMemberGrowthRule(@RequestBody MemberGrowthRuleRequest memberGrowthRuleRequest){
        return mememberGrowthRuleService.queryPage(memberGrowthRuleRequest);
    }

    @ApiOperation("新增成长值规则")
    @RequestMapping("addGrowthRule")
    public  RestResult<Long> addGrowthRule(@RequestBody MemberGrowthRuleRequest param){
        return mememberGrowthRuleService.insert(param);
    }

    @ApiOperation("编辑成长值规则")
    @RequestMapping("editGrowthRule")
    public  RestResult<Long> editGrowthRule(@RequestBody MemberGrowthRuleRequest param){
        return mememberGrowthRuleService.update(param);
    }

    @ApiOperation("删除成长值规则")
    @RequestMapping("delGrowthRule")
    public RestResult <Long> delGrowthRule(@RequestBody MemberGrowthRuleRequest param){
        return mememberGrowthRuleService.delByRuleId(param);
    }

    @ApiOperation("启用停用规则")
    @RequestMapping("updateGrowthRuleStatus")
    public RestResult<Long> updateGrowthRuleStatus(@RequestBody MemberGrowthRuleRequest request){
        return mememberGrowthRuleService.updateGrowthRuleStatus(request);
    }

    @ApiOperation("获取操作账号所属组织")
    @RequestMapping("getDeptNameByDeptId")
    public RestResult<String> getDeptNameByDeptId(@RequestBody MemberGrowthRuleRequest memberGrowthRuleRequest){
        return mememberGrowthRuleService.getDeptNameByDeptId(memberGrowthRuleRequest);
    }

    @ApiOperation("页面查询")
    @RequestMapping("getRulistByChild")
    public RestResult<PageResult<MemberGrowthRuleResponse>> getRulistByChild(@RequestBody MemberGrowthRuleRequest memberGrowthRuleRequest){
        RestResult<PageResult<MemberGrowthRuleResponse>> rulistByChild = new RestResult<> ();
        try {
             rulistByChild = mememberGrowthRuleService.getRulistByChild(memberGrowthRuleRequest);
        } catch (Exception e) {
            log.error("error",e);
            rulistByChild=RestResult.error("9999",e.getLocalizedMessage());
        }
        return rulistByChild;
    }

    @ApiOperation("更新会员表，流水表成长值")
    @RequestMapping("updateMemberGrowthInfo")
    public  RestResult<MemberGrowthActionApiResponse> updateMemberGrowthInfo(MemberGrowthActionApiRequest memberGrowthActionApiRequest){
      return  mememberGrowthRuleService.updateMemberGrowthInfo(memberGrowthActionApiRequest);
    };

    @ApiOperation("店铺成长值页面查询")
    @RequestMapping("getStoreMemberGrowthRule")
    public RestResult<PageResult<MemberGrowthRuleResponse>> getStoreMemberGrowthRule(@RequestBody MemberGrowthRuleRequest memberGrowthRuleRequest){
        return mememberGrowthRuleService.queryStoreMemberPage(memberGrowthRuleRequest);
    }

    @ApiOperation("启用停用店铺规则")
    @RequestMapping("updateStoreGrowthRuleStatus")
    public RestResult<Long> updateStoreGrowthRuleStatus(@RequestBody MemberGrowthRuleRequest request){
        return mememberGrowthRuleService.updateStoreGrowthRuleStatus(request);
    }

}
